/*
 *  Copyright (C) 1993  Robert Davis
 *
 *  This program is free software; you can redistribute it and/or
 *  modify it under the terms of Version 2, or any later version, of 
 *  the GNU General Public License as published by the Free Software 
 *  Foundation.
 */


static char RCSId[]="$Id: SeriesTicsPane.m,v 1.5 1993/05/04 16:22:42 davis Exp $";

#import <appkit/Application.h>
#import <appkit/Form.h>
#import <appkit/FormCell.h>
#import <appkit/View.h>

#import "SeriesTicsPane.h"
#import "Status.h"
#import "StatusTics.h"
#import "TicOptionsPanel.h"


@implementation SeriesTicsPane

- init
{
    [super init];

    [NXApp loadNibSection: "SeriesTicsPane.nib"
		    owner: self
		withNames: NO
		 fromZone: [self zone]];

    return self;
}



- (BOOL)updateStatus:aStatus doc:aDoc
{
    BOOL	enabled;

    [super updateStatus:aStatus doc:aDoc];

    enabled = status && doc;
    if (enabled) {
	int	coord = [doc coord];

	[startField setDoubleValue:[status ticStartCoord:coord]];
	[incrementField setDoubleValue:[status ticIncrementCoord:coord]];
	[endField setDoubleValue:[status ticEndCoord:coord]];
    }

    [startField setEnabled:enabled];
    [incrementField setEnabled:enabled];
    [endField setEnabled:enabled];

    return NO;
}


- selectControl:sender
{
    [seriesForm selectText:self];
    return self;
}


- setTicsSeries:sender
{
    int		coord = [doc coord];
    double	start = [startField doubleValue];
    double	incr = [incrementField doubleValue];
    double	end = [endField doubleValue];
    int		index = [sender selectedIndex];

    /*
     *  The increment must take us from the start to the end.  And the
     *  end must be larger than the start (gnuplot help says this is
     *  not true, but it doesn't seem to work otherwise).
     */
//    if (((start + incr) <= start) || (start >= end))
    if (((start + incr) <= start) || (start >= end))
 	[self forceUpdateStatus:status doc:doc];

    else {
 	FormCell *selectedCell = [sender selectedCell];

 	if (selectedCell == startField)
 	    [status setTicStartCoord:coord to:start];
 	else if (selectedCell == incrementField)
 	    [status setTicIncrementCoord:coord to:incr];
 	else
 	    [status setTicEndCoord:coord to:end];
    }

    return self;
}


// Shuts up the compiler about unused RCSId
- (const char *) rcsid
{
    return RCSId;
}


@end
